<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    ul,
    li {
      list-style: none;
    }

    .container {
      width: 1000px;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }

    .title {
      margin: 100px auto 20px;
      height: 60px;
      font-size: 32px;
    }

    .item {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      width: 600px;
      margin: 0 auto;
    }

    .list {
      width: 180px;
      height: 80px;
      border: 2px solid #eee;
      text-align: center;
      line-height: 80px;
      margin-bottom: 10px;
    }

    #btn {
      width: 120px;
      height: 60px;
      font-size: 20px;
      margin-top: 20px;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="title">XXX抽饭系统</div>
    <div class="food">
      <ul class="item" id="item">
        <!-- <li class="list">1</li>
        <li class="list">2</li>
        <li class="list">3</li>
        <li class="list">4</li>
        <li class="list">5</li>
        <li class="list">6</li>
        <li class="list">7</li>
        <li class="list">8</li>
        <li class="list">9</li> -->
      </ul>
    </div>
    <input type="button" value="点击" id="btn"></button>
  </div>
  <script>

    var item = document.getElementsByClassName('item')[0];
    var _change = document.getElementById('btn');
    var _li = document.getElementsByTagName('li');
    var foods = ['鱼香肉丝', '烤肉拌饭', '麻辣香锅', '老碗面', '黄焖鸡', '羊肉烩面', '麻辣烫', '豆花鸡', '蛋包饭'];
    var str = '';
    for (var i = 0; i < foods.length; i++) {
      str += '<li class="list">' + foods[i] + '<li>';
    }
    item.innerHTML = str;
    btn.onclick = function () {
      if (this.value === "点击") {
        //定时
        timeId = setInterval(function () {
          //清空所有颜色
          for (var j = 0; j < foods.length; j++) {
            _li[j].style.background = "";
          }
          //留下当前颜色
          var rade= Math.floor(foods.length * Math.random());
          console.log(rade);
          _li[rade].style.background = "orange";
        }, 100);
        this.value = "停止";
      } else {
        //清除计时器
        clearInterval(timeId);
        this.value = "点击";
      }
    }


  </script>
</body>

</html>